//
//  JHSelectionToolBar.m
//  JHAssetsPhotoPickerViewController
//
//  Created by admin on 15/11/20.
//  Copyright © 2015年 mohe. All rights reserved.
//

#import "JHSelectionToolBar.h"

@implementation JHSelectionToolBar

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        doneItem = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(doneAction)];
        UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
        _selectedCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        [_selectedCountLabel setBackgroundColor:[UIColor colorWithRed:72.0f/255.0f green:119.0f/255.0f blue:216.0f/255.0f alpha:1]];
        [_selectedCountLabel setTextAlignment:NSTextAlignmentCenter];
        [_selectedCountLabel setTextColor:[UIColor whiteColor]];
        [_selectedCountLabel.layer setCornerRadius:_selectedCountLabel.bounds.size.width/2.0f];
        [_selectedCountLabel.layer setMasksToBounds:YES];
        UIBarButtonItem *countItem = [[UIBarButtonItem alloc]initWithCustomView:_selectedCountLabel];
        [doneItem setEnabled:NO];
        [fixedSpace setWidth:self.frame.size.width-100];
        [_selectedCountLabel setHidden:YES];
        [self setItems:@[fixedSpace, countItem, doneItem]];

    }
    return self;
}
- (void)setSelectedCount:(NSInteger)selectedCount
{
    _selectedCount = selectedCount;
    [_selectedCountLabel setText:[NSString stringWithFormat:@"%ld", (long)_selectedCount]];
    [_selectedCountLabel setHidden:(_selectedCount == 0)];
    [doneItem setEnabled:selectedCount];
}
- (void)doneAction
{
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
